import type { TableData } from '@arco-design/web-vue/es/table/interface';
import http from '@/utils/http'
import {QueryRequest} from "@/api/system/level";

/**
 * 用户查询请求
 */
export interface UserQueryRequest{
  username?: string;
}
export interface PageQueryRequest extends QueryRequest, PageQuery {}


/**
 * 用户查询响应
 */
export interface UserQueryResponse extends TableData {
  id: number;
  realname: string;
  nickname: string;
  gender: number;
  avatar: string;
  mobile: string;
  email: string;
  position_id: number;
  username: string;
  password: string;
  salt: string;
  intro: string;
  status: number;
  note: string;
  login_time?: number;
  create_time?: number;
  update_time?: number;
  // roles: Array<RoleQueryResponse>;
}

/**
 * 用户更新请求
 */
export interface UserUpdateRequest {
  id?: number;
  status?: number;
  roles?: any;
  password?: string;
  username?: string;
  nickname?: string;
  mobile?: string;
  email?: string;
  sex?: number;
}

/**
 * 查询用户(分页)
 */
export function getUserList(params: PageQueryRequest) {
  return http.get<PageRes<UserQueryResponse[]>>('/admin/user/index', params);
}
/**
 * 修改用户状态
 */
export function updateUserStatus(request: UserUpdateRequest) {
  return http.post('/admin/user/status', request);
}
/**
 * 通过id数组批量删除用户
 */
export function batchDeleteUser(idList: Array<number |string>) {
  return http.post('/admin/user/delete', {
    id: idList,
  });
}

/**
 * 通过 id 删除用户
 */
export function deleteUser(id: number) {
  return http.post('/admin/user/delete', { id });
}
/**
 * 通过 id 重置用户密码
 */
export function resetUserPassword(request: UserUpdateRequest) {
  return http.post('/admin/user/updatePwd', request);
}

/**
 * 查询用户的 roleId
 */
export function getUserRoleIdList(userId: number) {
  return http.get('/admin/user/getRoles',{ userId});
}
/**
 * 修改用户角色
 */
export function updateUserRole(request: UserUpdateRequest) {
  return http.put('/admin/user/updateRoles', request);
}

/**
 * 通过 id 新增更新用户
 */
export function updateUser(request: UserUpdateRequest) {
  return http.put('/admin/user/edit', request);
}
